home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
-
- main()
- {
- char* remote_addr;
-
- printf("Content-type: text/html\n\n");
-
- printf("<HTML>\n");
- printf("<HEAD><TITLE>CGI Script How-to: Test Script</TITLE></HEAD>\n");
- printf("<BODY>\n");
-
- printf("<H1>CGI Script How-to<BR>determine the client machine's name</H1>\n");
-
- remote_addr = getenv("REMOTE_ADDR");
-
- /*
- * Don't assume an environment variable will always be defined and
- * especially in a C program where an undefined string (or NULL address)
- * when used in a string comparison function (strcmp) or print statement
- * may cause the program to abort or have unpredictable results.
- *
- * Check the value returned by the getenv function.
- */
-
- if (remote_addr != NULL)
- {
- printf("Your Internet address is <B>%s</B>\n", remote_addr);
- }
- else
- {
- printf("I don't know your Internet address. Who are you?\n");
- }
-
- printf("</BODY></HTML>\n");
- exit(0);
- }
-
- /*
- * end of chkaddr.c
- */
-